<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<table id="formatData"></table>  
<div id="formatGrid_bar" style="padding:5px;height:auto; display: none">
		<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true" onclick="appendClass()">添加</a>
		<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-edit',plain:true" onclick="editClass()">编辑</a>
</div>
<input id="idValue" type="hidden"/>
<script type="text/javascript">
//获取左侧树中选择的节点id   
var nodeId=$('#class-tree').tree('getSelected').id;
$("#idValue").val(nodeId);//将id设置到隐藏域
 var  classObj=$('#formatData').datagrid({
			singleSelect:true,
			url:'format/findFormatById',
			queryParams:{id:nodeId},
			striped:true,
			loadMsg:"正在加载中...",
			remoteSort:false,
			fit:true,
			toolbar:"#formatGrid_bar",
			columns:[[
			  		{field:'gfId',sortable:true,align:'center',checkbox:true},
			  		{field:'cId',title:'商品类目ID',width:100,align:'center'},
			  		{field:'cName',title:'商品类目名',width:100,align:'center'},
			  		{field:'gfParamData',title:'规格(只显示分组名)',width:300,align:'center',
			  			formatter:formatItemParamData	
			  		},
			  		{field:'gfCreateTime',title:'创建时间',width:150,align:'center',
			  			formatter: function(value,row,index){
							return getDate(row.gfCreateTime.toString());
			  			}	
			  		},
			  		{field:'gfUpdateTime',title:'更新时间',width:150,align:'center',
			  			formatter: function(value,row,index){
			  				if(row.gfUpdateTime!=""&&row.gfUpdateTime!=undefined){
			  					return getDate(row.gfUpdateTime.toString());
			  				}
							
			  			}		
			  		}]]
			
		}); 
 //格式化数据表格中的规格json数据
 function formatItemParamData(value , index){
		var json = JSON.parse(value);
		var array = [];
		$.each(json,function(i,e){
			array.push(e.group);
		});
		return array.join(",");
	}
 
 function appendClass(){
	 if($('#formatData').datagrid('getRows').length>0){
		 $.messager.alert('提示','规格已存在,请编辑即可!','info');
	 }else{
		 commenUtil.createWindow({
			 			id:nodeId,
			 			title:'添加',
			     		url : "back/goods-format-add",
			     	})
	 }
 }
 function editClass(){
	 if($('#formatData').datagrid('getRows').length==0){
		 $.messager.alert('提示','请先添加规格数据!','info');
	 }else{
		 commenUtil.createWindow({
			 			id:nodeId,
			 			title:'修改',
			     		url : "back/goods-format-edit",
			     	})
	 }
 }

 
 
</script>